package com.qf.controller;

import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author sunyamei
 * @version V1.0
 * @Project springmvc_Demo
 * @Package com.qf.controller
 * @Description:
 * @Date 2022/7/15 17:08
 */
@Controller
@RequestMapping("/users")
public class UserController {

    @Autowired
    private UserService userService;
//
//    @GetMapping
//    public  String  findAll(){
//        List<User> users = userService.findAll();
//        return  "user";
//    }

    @GetMapping
    public  String queryPage(Model model,
                             @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum,
                             @RequestParam(name = "pageSize",defaultValue = "2")Integer pageSize){
        Object o = userService.findPage(pageNum, pageSize);
        model.addAttribute("data", o);
        return  "userPro";

    }

    /**
     * 根据名字删除
     * @param name
     */
    @GetMapping
    public  void deleteByName(String name){
         userService.deleteByName("1111");
    }
}
